package com.zlc.proxy;

import java.lang.reflect.Proxy;

import com.zlc.proxy.ViewChangeBgTool.ButtonResource;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class ProxyActivity extends Activity {

	private Button button1;
	private Button button2;
	private Button button3;

	private ViewChangeBgTool mViewChangeBgTool;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		button1 = (Button) findViewById(R.id.button1);
//		button2 = (Button) findViewById(R.id.button2);
//		button3 = (Button) findViewById(R.id.button3);
//		initButtonClickBg();
//		
//		button1.performClick();
		
		TrendsProxyOnClickListener tpcl = new TrendsProxyOnClickListener(ocl);
		
		OnClickListener oo = (OnClickListener) Proxy.newProxyInstance(getClassLoader(), ocl.getClass().getInterfaces(), tpcl);
		
		button1.setOnClickListener(oo);
	}

	private OnClickListener ocl = new OnClickListener() {
		@Override
		public void onClick(View v) {
			v.setSelected(true);
			Toast.makeText(ProxyActivity.this, "click1111111111111",
					Toast.LENGTH_SHORT).show();
		}
	};

	private OnClickListener oc2 = new OnClickListener() {
		@Override
		public void onClick(View v) {
			Toast.makeText(ProxyActivity.this, "click2222222222",
					Toast.LENGTH_SHORT).show();
		}
	};

	private OnClickListener oc3 = new OnClickListener() {
		@Override
		public void onClick(View v) {
			Toast.makeText(ProxyActivity.this, "click333333333333333",
					Toast.LENGTH_SHORT).show();
		}
	};

	private void initButtonClickBg() {
		mViewChangeBgTool = new ViewChangeBgTool(this);
		mViewChangeBgTool.addButton(new ButtonResource(button1, R.drawable.a,
				R.drawable.a_1));
		mViewChangeBgTool.addButton(new ButtonResource(button2, R.drawable.b,
				R.drawable.b_1));
		mViewChangeBgTool.addButton(new ButtonResource(button3, R.drawable.c,
				R.drawable.c_1));
		
		button1.setOnClickListener(new ProxyOnClickListaner(ocl,
				mViewChangeBgTool));
		button2.setOnClickListener(new ProxyOnClickListaner(oc2,
				mViewChangeBgTool));
		button3.setOnClickListener(new ProxyOnClickListaner(oc3,
				mViewChangeBgTool));
	}
}